﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lfm.EndPoints
{
    public class Chart
    {
        /// <summary>
        /// Get the hyped artists chart
        /// </summary>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <returns>Hyped Artists chart</returns>
        public static async Task<List<lfm.Artist>> getHypedArtists(Int32? Page, Int32? Limit)
        {
            String s = String.Format("{0}&method=chart.getHypedArtists", Base.APIUrl);
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Chart.getTopArtists(await Base.DownloadString(u));
        }

        /// <summary>
        /// Get the hyped tracks chart
        /// </summary>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <returns>hyped tracks chart</returns>
        public static async Task<List<lfm.Track>> getHypedTracks(Int32? Page, Int32? Limit)
        {
            String s = String.Format("{0}&method=chart.getHypedTracks", Base.APIUrl);
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Generic.getTracks(await Base.DownloadString(u));
        }

        /// <summary>
        /// Get the most loved tracks chart
        /// </summary>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <returns>Most loved tracks chart</returns>
        public static async Task<List<lfm.Track>> getLovedTracks(Int32? Page, Int32? Limit)
        {
            String s = String.Format("{0}&method=chart.getLovedTracks", Base.APIUrl);
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Generic.getTracks(await Base.DownloadString(u));
        }

        /// <summary>
        /// Get the top artists chart
        /// </summary>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <returns>Top tags chart</returns>
        public static async Task<List<lfm.Artist>> getTopArtists(Int32? Page, Int32? Limit)
        {
            String s = String.Format("{0}&method=chart.getTopArtists", Base.APIUrl);
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Chart.getTopArtists(await Base.DownloadString(u));
        }

        /// <summary>
        /// Get the top tags chart
        /// </summary>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <returns>Top tags chart</returns>
        public static async Task<List<lfm.Tag>> getTopTags(Int32? Page, Int32? Limit)
        {
            String s = String.Format("{0}&method=chart.gettoptags", Base.APIUrl);
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Generic.getFullTags(await Base.DownloadString(u));
        }

        /// <summary>
        /// Get the top tracks chart
        /// </summary>
        /// <param name="Page">The page number to fetch. Defaults to first page</param>
        /// <param name="Limit">The number of results to fetch per page. Defaults to 50</param>
        /// <returns>Top tracks chart</returns>
        public static async Task<List<lfm.Track>> getTopTracks(Int32? Page, Int32? Limit)
        {
            String s = String.Format("{0}&method=chart.getTopTracks", Base.APIUrl);
            if (Page.HasValue) s += "&page=" + Page.Value.ToString();
            if (Limit.HasValue) s += "&limit=" + Limit.Value.ToString();

            Uri u = new Uri(s, UriKind.RelativeOrAbsolute);
            return await Parser.Generic.getTracks(await Base.DownloadString(u));
        }
    }
}
